package com.sharewin.exception;

import com.sharewin.bean.ResponseVO;
import com.sharewin.constant.ServerResponseEnum;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author chenghai
 * @date 2021年07月17日 14:18
 * 统一异常处理
 */
@RestControllerAdvice
public class UserExceptionHandler {

    @ExceptionHandler(UnauthorizedException.class)
    @ResponseStatus(HttpStatus.UNAUTHORIZED)
    public ResponseVO UnAuthorizedExceptionHandler(UnauthorizedException e) {
        return ResponseVO.error(ServerResponseEnum.UNAUTHORIZED);
    }
}
